import { Behaviour, getGameObjectById, Transform, core } from "./gameengine";
import { ColliderSystem } from "./rect/ColliderSystem";
import { RectCollider, RectColliderType } from "./rect/RectCollider";
import { MonsterBehaviour } from "./monster";
import { MarshalMonsterAttackState } from "./Marshal";

export class disappear extends Behaviour {


    private speedX = 0;
    private speedY = 0;


    protected onStart() {
    }

    protected onUpdate(advancedTime: number) {
        const colliderSystem = getGameObjectById("Game").getScript(ColliderSystem);
        const collider = this.displayObject.getScript(RectCollider);
        const nextCollider = {
            left: collider.left + -4,
            right: collider.right + 4,
            top: collider.top + -4,
            bottom: collider.bottom + 4
        }
        const hitTestResult1 = colliderSystem.check(nextCollider, RectColliderType.MAINROLE);
        if (hitTestResult1) {
            colliderSystem.removeRectCollider(collider);
            // if(hp<=0)
            const monsterBehaviour = this.displayObject.getScript(MonsterBehaviour);
            const marshal = monsterBehaviour.marshal;
            if (marshal) {
                marshal.changeState(new MarshalMonsterAttackState(this.displayObject));
            }

        }

    }


}